<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>发布预警信息</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
  <style>
    :root {
      --primary-color: #3498db;
      --danger-color: #e74c3c;
      --warning-color: #f39c12;
      --success-color: #2ecc71;
      --light-color: #ecf0f1;
      --dark-color: #2c3e50;
      --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }

    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      font-family: 'Noto Sans SC', sans-serif;
    }

    body {
      background: linear-gradient(135deg, #f5f7fa 0%, #dfe6f0 100%);
      min-height: 100vh;
      padding: 20px;
      color: var(--dark-color);
    }

    .container {
      max-width: 800px;
      margin: 30px auto;
      background: white;
      border-radius: 12px;
      box-shadow: var(--shadow);
      padding: 30px;
      position: relative;
      overflow: hidden;
    }

    .container::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 5px;
      background: linear-gradient(90deg, var(--primary-color), var(--danger-color));
    }

    h2 {
      text-align: center;
      margin-bottom: 30px;
      color: var(--dark-color);
      font-size: 28px;
      position: relative;
      padding-bottom: 15px;
    }

    h2::after {
      content: '';
      position: absolute;
      bottom: 0;
      left: 50%;
      transform: translateX(-50%);
      width: 80px;
      height: 3px;
      background: var(--primary-color);
      border-radius: 3px;
    }

    .message {
      padding: 15px;
      margin-bottom: 25px;
      border-radius: 8px;
      font-weight: 500;
      text-align: center;
      animation: fadeIn 0.5s ease;
    }

    .success {
      background-color: rgba(46, 204, 113, 0.2);
      color: var(--success-color);
      border-left: 4px solid var(--success-color);
    }

    .error {
      background-color: rgba(231, 76, 60, 0.2);
      color: var(--danger-color);
      border-left: 4px solid var(--danger-color);
    }

    .form-group {
      margin-bottom: 25px;
    }

    label {
      display: block;
      margin-bottom: 8px;
      font-weight: 500;
      color: var(--dark-color);
    }

    input[type="text"],
    textarea,
    select {
      width: 100%;
      padding: 12px 15px;
      border: 1px solid #ddd;
      border-radius: 8px;
      font-size: 16px;
      transition: all 0.3s ease;
      background-color: #f9f9f9;
    }

    input[type="text"]:focus,
    textarea:focus,
    select:focus {
      outline: none;
      border-color: var(--primary-color);
      box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
      background-color: white;
    }

    textarea {
      resize: vertical;
      min-height: 120px;
    }

    select {
      appearance: none;
      background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
      background-repeat: no-repeat;
      background-position: right 10px center;
      background-size: 15px;
    }

    .btn-submit {
      width: 100%;
      padding: 14px;
      background-color: var(--primary-color);
      color: white;
      border: none;
      border-radius: 8px;
      font-size: 16px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.3s ease;
      margin-top: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
    }

    .btn-submit:hover {
      background-color: #2980b9;
      transform: translateY(-2px);
      box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
    }

    .btn-submit:active {
      transform: translateY(0);
    }

    .publisher-info {
      margin-top: 25px;
      padding: 12px;
      background-color: #f8f9fa;
      border-radius: 8px;
      text-align: center;
      font-size: 14px;
      color: #6c757d;
      border-left: 4px solid var(--primary-color);
    }

    .severity-indicator {
      display: inline-block;
      width: 12px;
      height: 12px;
      border-radius: 50%;
      margin-right: 8px;
    }

    .severity-low { background-color: var(--success-color); }
    .severity-medium { background-color: var(--warning-color); }
    .severity-high { background-color: var(--danger-color); }

    @keyframes fadeIn {
      from { opacity: 0; transform: translateY(-10px); }
      to { opacity: 1; transform: translateY(0); }
    }

    @media (max-width: 768px) {
      .container {
        padding: 20px;
        margin: 15px;
      }

      h2 {
        font-size: 24px;
      }
    }
  </style>
</head>
<body>

<div class="container">
  <h2><i class="fas fa-bullhorn"></i> 发布预警信息</h2>

  <% if (request.getAttribute("message") != null) { %>
  <div class="message <%= request.getAttribute("message").toString().contains("成功") ? "success" : "error" %>">
    <i class="fas <%= request.getAttribute("message").toString().contains("成功") ? "fa-check-circle" : "fa-exclamation-circle" %>"></i>
    <%= request.getAttribute("message") %>
  </div>
  <% } %>

  <form action="resources" method="post">
    <div class="form-group">
      <label for="title"><i class="fas fa-heading"></i> 标题</label>
      <input type="text" id="title" name="title" required placeholder="请输入预警标题...">
    </div>

    <div class="form-group">
      <label for="content"><i class="fas fa-align-left"></i> 内容</label>
      <textarea id="content" name="content" rows="5" required placeholder="请输入详细的预警内容..."></textarea>
    </div>

    <div class="form-group">
      <label for="severity"><i class="fas fa-exclamation-triangle"></i> 预警等级</label>
      <select id="severity" name="severity" required>
        <option value="低"><span class="severity-indicator severity-low"></span> 低</option>
        <option value="中"><span class="severity-indicator severity-medium"></span> 中</option>
        <option value="高"><span class="severity-indicator severity-high"></span> 高</option>
      </select>
    </div>

    <!-- 发布人输入框（适配登录/未登录状态） -->
    <div class="form-group">
      <label for="publisher"><i class="fas fa-user"></i> 发布人</label>
      <% if (session.getAttribute("username") != null) { %>
      <!-- 已登录状态：显示用户名且不可修改 -->
      <input type="text" id="publisher" name="publisher"
             value="<%= session.getAttribute("username") %>"
             required
             readonly
             class="bg-gray-50 cursor-not-allowed">
      <p class="text-xs text-gray-500 mt-1">已从登录信息获取发布人，不可修改</p>
      <% } else { %>
      <!-- 未登录状态：允许手动输入发布人 -->
      <input type="text" id="publisher" name="publisher"
             required
             placeholder="请输入您的姓名或身份...">
      <p class="text-xs text-gray-500 mt-1">请输入您的身份信息作为发布人标识</p>
      <% } %>
    </div>

    <button type="submit" class="btn-submit">
      <i class="fas fa-paper-plane"></i> 发布预警信息
    </button>
  </form>

  <% if (session.getAttribute("username") != null) { %>
  <div class="publisher-info">
    <i class="fas fa-info-circle"></i> 当前登录用户: <strong><%= session.getAttribute("username") %></strong>
  </div>
  <% } %>
</div>

</body>
</html>